<?
/*----------------------------------------------------------------------
          (C) Bobtail-Bear 2006 	小飞熊新一代下载系统
          	代码编写：小飞熊	版权所有：小飞熊[L.F.Bear]
				官方网站/技术支持：http://www.bobtail-bear.cn
------------------------------------------------------------------------
          (C) Bobtail-Bear 2006 	L.F.Bear's New Download Sysytem
          	Powered by L.F.Bear  Copyright L.F.Bear's Home(R)
               Official Web/Support：http://www.bobtail-bear.cn
-----------------------------------------------------------------------*/

//本页脚本功能：首页

$act=$_GET[act];
$thispage="index.php";
$searchbar="y";
require("header.php"); 
require("include/config.index.php");

//调入统计数据
$soft_num=readf($path_soft."/number");
$news_num=readf($path_news."/number");
$user_num=readf($path_user."/number");

//调入公告内容
$affiche=file("include/config.aff.php");
$affiche_num=count($affiche);
for($j=1;$j<$affiche_num;$j++){
$notice=explode(",",$affiche[$j]);
$notice_msg.="<font color=#666666>[".$notice[0]."] </font><font color=#669900>".$notice[1]."</font>：<font color=#0066CC>".$notice[2]."</font>&nbsp;&nbsp;&nbsp;&nbsp;";
}

//调入网站链接
$link=file("include/linkinfo.php");
$link_num=count($link);
for($i=1;$i<$link_num;$i++)
{
$link_info=explode("|",$link[$i]);
if($link_info[0]=="y"){
if(trim($link_info[4])!="0") 
$link_pic="<tr><td width=\"91\" align=\"center\" valign=\"middle\"><img src=\"$link_info[4]\"  width=\"88\" height=\"31\" border=\"0\"/>";
else $link_pic="<tr><td width=\"91\" align=\"center\" valign=\"middle\">";
$link_show.=$link_pic.
"<a href=\"$link_info[2]\" title=\"$link_info[3]\" target=\"_blank\">$link_info[1]</a><br><br></td></tr>";
}
}
//调入推荐TOP10
$top10_info=@file("cache/recommend.php");
$top10_show="<table width=\"175\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>";
for($tn=0;$tn<count($top10_info);$tn++)
{
unset($temp);
$temp=explode("|",$top10_info[$tn]);
$top10_show.="<li><a href=view.php?id=$temp[0] title=\"$temp[1]\"> $temp[1] </a></li>";
}
if(count($top10_info)==0) $top10_show.=$p_lang[1];
$top10_show.="</td></tr></table>";

//刷新下载top10
if($act=="renewtop10" && $soft_num>0)
{
unset($dnt);
for($fn=1;$fn<=$soft_num;$fn++)
{
if(!file_exists($path_soft."/click/".$fn.".dnt")) $dnt[$fn]=0;
else $dnt[$fn]=readf($path_soft."/click/".$fn.".dnt");
}
arsort($dnt);
unset($newitem);
$l=0;
for(reset($dnt);$key=key($dnt);next($dnt))
{
$l++;
if($l>11) break;
if($dnt[$key]==0) break;
unset($tempx);
$tempx=readf($path_soft."/".$key.".dat");
$tempx=explode("|",$tempx);
$newitem.=$key."|".$tempx[3]."|".$tempx[2]."|".$tempx[6]."|".$tempx[7]."|".$tempx[5]."\n";
}
writef("cache/top_soft.php",$newitem,"w");
weblog("102","$p_lang[5]","green","$p_lang[2]","$p_lang[3]");
echo("<Meta http-equiv='Refresh' Content='0; Url=index.php'>");
}

//调入下载TOP10
$td10_info=@file("cache/top_soft.php");
$td_show="<table width=\"175\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>";

for($dn=0;$dn<count($td10_info);$dn++)
{
unset($tempy);
$tempy=explode("|",$td10_info[$dn]);
$td_show.="<li><a href=view.php?id=$tempy[0] title=\"$tempy[1]\"> $tempy[1] </a></li>";
}
if(count($td10_info)==0) $td_show.=$p_lang[1];

$td_show.="</td></tr></table>";

//刷新文章top10
if($act=="renewarttop10")
{
unset($dnt);
for($fn=1;$fn<=$soft_num;$fn++)
{
if(!file_exists($path_news."/click/".$fn.".brt")) $dnt[$fn]=0;
else $dnt[$fn]=readf($path_news."/click/".$fn.".brt");
}
arsort($dnt);
unset($newitem);
$l=0;
for(reset($dnt);$key=key($dnt);next($dnt))
{
$l++;
if($l>11) break;
if($dnt[$key]==0) break;
unset($tempx);
$tempx=readf($path_news."/".$key.".php");
$tempx=explode("|",$tempx);
$newitem.=$key."|".$tempx[3]."|".$tempx[2]."|".$tempx[4]."|".$tempx[5]."\n";
}
writef("cache/top_news.php",$newitem,"w");
weblog("102","$p_lang[6]","green","$p_lang[2]","$p_lang[3]");
echo("<Meta http-equiv='Refresh' Content='0; Url=index.php'>");
}


//调入文章TOP10
$td_news_info=@file("cache/top_news.php");
$td_show_news="<table width=\"175\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>";

for($dn_news=0;$dn_news<count($td_news_info);$dn_news++)
{
unset($tempy);
$tempy=explode("|",$td_news_info[$dn_news]);
$td_show_news.="<li><a href=news.php?id=$tempy[0] title=\"$tempy[1]\"> $tempy[1] </a></li>";
}
if(count($td_news_info)==0) $td_show_news.=$p_lang[1];

$td_show_news.="</td></tr></table>";



//调入快捷分类内容
unset($now_num);unset($list_num);unset($list_info);unset($lcount);
$now_num=readf($path_soft."/number");
if($now_num>0)
{
$list_num=ceil($now_num/100);
$list_info=file("cache/soft_list_".$list_num.".php");
$lcount=count($list_info)-1;
$list_1="<br><table width=\"290\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
$list_2="<br><table width=\"290\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
$list_3="<br><table width=\"290\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
$list_4="<br><table width=\"290\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
//检测变量初始化
$num1=0;$num2=0;$num3=0;$num4=0;
$stop1=0;$stop2=0;$stop3=0;$stop4=0;
while(!($list_num==1 && $lcount==-1) )
{
if($stop1*$stop2*$stop3*$stop4==1) break;
if($lcount<0) {$list_num--;$list_info=file("cache/soft_list_".$list_num.".php");$lcount=count($list_info)-1;}
unset($thisone);

$thisone=explode("|",$list_info[$lcount]);

if($classtype==1) {$ctype=$thisone[4];$c_show_name="mainclass";} 
else {$ctype=$thisone[5];$c_show_name="subclass";}
switch($ctype)
{
case $class_1:
$num1++;
if($num1<=$show_num2)
{if(strlen($thisone[2])>=26)
$show_name=cut_str($thisone[2],13,0,"UTF-8");
else $show_name=$thisone[2];
$list_1.="
  <tr>
    <td width=\"210\" class=\"markedText5\"><a href=view.php?id=$thisone[0] title=\"$thisone[2]\" target=\"_blank\">$show_name</a></td>
    <td width=\"80\" class=\"markedText5\"> $thisone[6] </td>
  </tr> ";}
else $stop1=1;
break;
case $class_2:
$num2++;
if($num2<=$show_num2)
{if(strlen($thisone[2])>=26)
$show_name=cut_str($thisone[2],13,0,"UTF-8");
else $show_name=$thisone[2];
$list_2.="
  <tr>
    <td width=\"210\" class=\"markedText5\"><a href=view.php?id=$thisone[0] title=\"$thisone[2]\" target=\"_blank\">$show_name</a></td>
    <td width=\"80\" class=\"markedText5\"> $thisone[6] </td>
  </tr> ";}
else $stop2=1;
break;
case $class_3:
$num3++;
if($num3<=$show_num2)
{if(strlen($thisone[2])>=26) 
$show_name=cut_str($thisone[2],13,0,"UTF-8");
else $show_name=$thisone[2];
$list_3.="
  <tr>
    <td width=\"210\" class=\"markedText5\"><a href=view.php?id=$thisone[0] title=\"$thisone[2]\" target=\"_blank\">$show_name</a></td>
    <td width=\"80\" class=\"markedText5\"> $thisone[6] </td>
  </tr> ";}
else $stop3=1;
break;
case $class_4:
$num4++;
if($num4<=$show_num2)
{if(strlen($thisone[2])>=26) 
$show_name=cut_str($thisone[2],13,0,"UTF-8");
else $show_name=$thisone[2];
$list_4.="
  <tr>
    <td width=\"210\" class=\"markedText5\"><a href=view.php?id=$thisone[0] title=\"$thisone[2]\" target=\"_blank\">$show_name</a></td>
    <td width=\"80\" class=\"markedText5\"> $thisone[6] </td>
  </tr> ";}
else $stop4=1;
break;

}
$lcount--;
}
$soft_info.="</table>";
$list_1.="</table>";
$list_2.="</table>";
$list_3.="</table>";
$list_4.="</table>";

//调入最新软件

//判断是否直接从缓存读出软件信息
$nowtime=date(YmdHis);
$lasttime=readf("cache/newsoft.tim");
$befile=file_exists("cache/newsoft.php") && file_exists("cache/newsoft.tim");
if($nowtime-$lasttime>10000 || $act==renewsoft || $befile==false)
{
$b_num=0;

$now_num=readf($path_soft."/number");
$list_num=ceil($now_num/100);
$temp_info=file("cache/soft_list_".$list_num.".php");
$lcount=count($temp_info)-1;

$show_num1>=$now_num ? $show_new_num=$now_num : $show_new_num=$show_num1;

while($b_num<=$show_new_num && $lcount>=0)
{
unset($tempz);
$tempz=explode("|",$temp_info[$lcount]);
if($tempz[1]==1 && $tempz[2]!="" && $tempz[2]!=$p_lang[0])
{$list_info[$b_num]=$temp_info[$lcount];$b_num++;}
$lcount--;
}

while($b_num<$show_new_num+1 && $list_num>1)
{
$list_num--;
$temp_info=file("cache/soft_list_".$list_num.".php");
$lcount=count($temp_info)-1;

while($b_num<=$show_new_num && $lcount>=0)
{
unset($tempz);
$tempz=explode("|",$temp_info[$lcount]);
if($tempz[1]==1 && $tempz[2]!="" && $tempz[2]!=$p_lang[0])
{$list_info[$b_num]=$temp_info[$lcount];$b_num++;}
$lcount--;
}
}

$soft_info="<br><table width=\"360\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
//echo $show_new_num;
$today=date(Y)."-".date(m)."-".date(d);$today_num=0;
writef("cache/newsoft.php","","w");
$wtime=date(YmdHis);
writef("cache/newsoft.tim",$wtime,"w");
for($i=0;$i<$show_new_num;$i++)
{
unset($thisone);
writef("cache/newsoft.php",$list_info[$i],"a");
$thisone=explode("|",$list_info[$i]);
//echo $list_info[$i];
showclassname($thisone[4],$thisone[5]);
$thedate=trim($thisone[6]);
if($thedate==$today) $today_num++ ;

if(strlen($thisone[2])>=26) 
//$show_name=substr($thisone[2],0,27)."..";
$show_name=cut_str($thisone[2],13,0,"UTF-8");
else $show_name=$thisone[2];

$soft_info.="
  <tr>
    <td width=\"90\" class=\"markedText5\">&nbsp;[<a href=sort.php?subclass=$thisone[5]>$classname[1]</a>]</td>
    <td width=\"200\" class=\"markedText5\"><a href=view.php?id=$thisone[0] title=\"$thisone[2]\" target=\"_blank\">$show_name</a></td>
    <td width=\"70\" class=\"markedText5\"> $thisone[6] </td>
  </tr> ";

}
$soft_info.="</table>";
weblog("102","$p_lang[7]","green","$p_lang[2]","$p_lang[4]");
if($act==renewsoft) echo("<Meta http-equiv='Refresh' Content='0; Url=index.php'>");
}

else
{
$soft_info="<br><table width=\"360\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
$today=date(Y)."-".date(m)."-".date(d);$today_num=0;
$list_info=file("cache/newsoft.php");
$lcount=count($list_info);
for($i=0;$i<$lcount;$i++)
{
unset($thisone);
$thisone=explode("|",$list_info[$i]);
showclassname($thisone[4],$thisone[5]);
$thedate=trim($thisone[6]);
if($thedate==$today) $today_num++ ;

if(strlen($thisone[2])>=26) 
$show_name=cut_str($thisone[2],13,0,"UTF-8");
else $show_name=$thisone[2];

$soft_info.="
  <tr>
    <td width=\"90\" class=\"markedText5\">&nbsp;[<a href=sort.php?subclass=$thisone[5]>$classname[1]</a>]</td>
    <td width=\"200\" class=\"markedText5\"><a href=view.php?id=$thisone[0] title=\"$thisone[2]\" target=\"_blank\">$show_name</a></td>
    <td width=\"70\" class=\"markedText5\"> $thisone[6] </td>
  </tr> ";

}

$soft_info.="</table>";

}

//判断是否直接从缓存读出文章信息

$lasttime_art=readf("cache/newart.tim");
$befile_art=file_exists("cache/newart.php") && file_exists("cache/newart.tim");
if($nowtime-$lasttime_art>10000 || $act==renewart || $befile_art==false)
{
$b_num_news=0;

$now_num_news=readf($path_news."/number");
$list_num_news=ceil($now_num_news/100);
$temp_info_news=file("cache/news_list_".$list_num_news.".php");
$lcount_news=count($temp_info_news)-1;

$show_num1>=$now_num_news ? $show_new_num_news=$now_num_news : $show_new_num_news=$show_num1;
unset($list_info);
while($b_num_news<=$show_new_num_news && $lcount_news>=0)
{
unset($tempz);
$tempz=explode("|",$temp_info_news[$lcount_news]);
if($tempz[1]==1 && $tempz[2]!="")
{$list_info[$b_num_news]=$temp_info_news[$lcount_news];$b_num_news++;}
$lcount_news--;
}

while($b_num_news<$show_new_num_news+1 && $list_num_news>1)
{
$list_num_news--;
$temp_info_news=file("cache/news_list_".$list_num_news.".php");
$lcount_news=count($temp_info_news)-1;

while($b_num_news<=$show_new_num_news && $lcount_news>=0)
{
unset($tempz);
$tempz=explode("|",$temp_info_news[$lcount_news]);
if($tempz[1]==1 && $tempz[2]!="")
{$list_info[$b_num_news]=$temp_info_news[$lcount_news];$b_num_news++;}
$lcount_news--;
}
}

$news_info="<br><table width=\"210\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";

writef("cache/newart.php","","w");
$wtime_art=date(YmdHis);
writef("cache/newart.tim",$wtime_art,"w");

//echo $show_new_num_news;
for($j=0;$j<$show_new_num_news;$j++)
{
unset($thisone);
writef("cache/newart.php",$list_info[$j],"a");
$thisone=explode("|",$list_info[$j]);
//echo $list_info[$j];


if(strlen($thisone[3])>=20) 
$show_name=cut_str($thisone[3],10,0,"UTF-8");
else $show_name=$thisone[3];
$thisone[5]=trim($thisone[5]);
if($thisone[3]!="")
$news_info.="
  <tr>
   <td width=\"75\" class=\"markedText5\">&nbsp;[$thisone[4]]</td>
    <td width=\"135\" class=\"markedText5\"><a href=news.php?id=$thisone[0] title=\"$thisone[3] [$p_lang[9]$thisone[5]]\" target=\"_blank\">$show_name</a></td>
  </tr> ";


}
$news_info.="</table>";
weblog("102","$p_lang[8]","green","$p_lang[2]","$p_lang[4]");
if($act==renewart) echo("<Meta http-equiv='Refresh' Content='0; Url=index.php'>");
}
else

{
$news_info="<br><table width=\"210\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";

$list_info_news=file("cache/newart.php");
$lcount_news=count($list_info_news);
for($j=0;$j<$lcount_news;$j++)
{
unset($thisone);
$thisone=explode("|",$list_info_news[$j]);

if(strlen($thisone[3])>=26) 
$show_name=cut_str($thisone[3],13,0,"UTF-8");
else $show_name=$thisone[3];
if($thisone[3]!="")
$news_info.="
  <tr>
   <td width=\"75\" class=\"markedText5\">&nbsp;[$thisone[4]]</td>
    <td width=\"135\" class=\"markedText5\"><a href=news.php?id=$thisone[0] title=\"$thisone[3] [$p_lang[9]$thisone[5]]\" target=\"_blank\">$show_name</a></td>
  </tr> ";
}
$news_info.="</table>";

}}
//用户登陆/显示用户信息部分
if($users=="n")
{
$div=f_l_list(2);
$skip=1;
}
$action=$_GET[action];
if($action=="loginout")
{
	setcookie("l_state","",time()-3600);
	session_destroy();
	$fb_title1=$p_lang[10];
	$fb_title2=$p_lang[11];
	$fb_msg=$p_lang[12];
	$fb_link="index.php";
	echo("<Meta http-equiv='Refresh' Content='2; Url=index.php'>");
	require("feedback.php");
}
if($action=="login")
{
	if($ccode=="y" && md5(md5($_POST[code]))!=$_SESSION[code]) 
	{
	$fb_title1=$p_lang[13];
	$fb_title2=$p_lang[14];
	$fb_msg=$p_lang[15];
	die(require("feedback.php"));
	}
	f_login($_POST[username],$_POST[userpass]);//登陆验证
	
	//判断是否加分并且加分
	if($uplevel1=="y" && !file_exists("include/bbs.php"))
	{
	if($lastlogin[1]==date(Ymd) && $lastlogin[0]<2) logingood($name123,$uplevel1_point,$path_user); 
	if($lastlogin[1]!=date(Ymd)) logingood($name123,$uplevel1_point,$path_user);
	}
    $fb_title1=$p_lang[16];
	$fb_title2=$_SESSION[f_name].$p_lang[17];
	$fb_msg=$p_lang[18];
	$fb_link="index.php";
	echo("<Meta http-equiv='Refresh' Content='2; Url=index.php'>");
	require("feedback.php");
}
if($skip!=1 && $_SESSION[f_login]=="yes" && $_COOKIE[l_state]=="ok")
$div=f_l_list(1);
elseif($skip!=1 && ($_SESSION[f_login]!="yes" || $_COOKIE[l_state]!="ok"))
{
$div=f_l_list(0);
}
print <<<EOT
<script language="javascript">
function checkform(theform) {
	if (theform.username.value=="" ) {
		alert('$p_lang[19]$p_lang[20]');
		return false; }
	if (theform.userpass.value=="" ) {
		alert("$p_lang[19]$p_lang[21]");
		return false; }
	if (theform.code.value=="" ) {
		alert("$p_lang[19]$p_lang[22]");
		return false; }
		}
</script>
EOT;

//输出到模版

	require("template.php");
	$page = new SmartTemplate( "index.html" );
	$page->assign('div',$div);
	$page->assign('notice_msg',$notice_msg);
	$page->assign('top10_show',$top10_show);
	$page->assign('soft_pic_1',$soft_pic_1);
	$page->assign('soft_intro_1',$soft_intro_1);
	$page->assign('soft_id_1',$soft_id_1);
	$page->assign('soft_pic_2',$soft_pic_2);
	$page->assign('soft_intro_2',$soft_intro_2);
	$page->assign('soft_id_2',$soft_id_2);
	$page->assign('soft_pic_3',$soft_pic_3);
	$page->assign('soft_intro_3',$soft_intro_3);
	$page->assign('soft_id_3',$soft_id_3);
	$page->assign('soft_pic_4',$soft_pic_4);
	$page->assign('soft_intro_4',$soft_intro_4);
	$page->assign('soft_id_4',$soft_id_4);
	$page->assign('soft_pic_5',$soft_pic_5);
	$page->assign('soft_intro_5',$soft_intro_5);
	$page->assign('soft_id_5',$soft_id_5);
	$page->assign('ad_code_1',$ad_code_1);
	$page->assign('td_show',$td_show);
	$page->assign('soft_info',$soft_info);
	$page->assign('news_info',$news_info);
	$page->assign('ad_code_2',$ad_code_2);
	$page->assign('td_show_news',$td_show_news);
	$page->assign('c_show_name',$c_show_name);
	$page->assign('class_name_1',$class_name_1);
	$page->assign('class_1',$class_1);
	$page->assign('list_1',$list_1);
	$page->assign('class_name_2',$class_name_2);
	$page->assign('class_2',$class_2);
	$page->assign('list_2',$list_2);
	$page->assign('class_name_3',$class_name_3);
	$page->assign('class_3',$class_3);
	$page->assign('list_3',$list_3);
	$page->assign('class_name_4',$class_name_4);
	$page->assign('class_4',$class_4);
	$page->assign('list_4',$list_4);
	$page->assign('soft_num',$soft_num);
	$page->assign('news_num',$news_num);
	$page->assign('user_num',$user_num);
	$page->assign('link_show',$link_show);
	$page->assign('imagepath',$imagepath);
	$page->assign('t_lang',$t_lang);
	$page->output();

require("footer.php"); 
?>